#pragma once

#include "texturebillboardeffect.h"
#include <osgUtil\CullVisitor>
#include <osgViewer\View>

namespace VrDataCore
{
	class BlinkLightUpdateCallback;

	class VRDATACORE_EXPORT BlinkLightEffect:public TextureBillboardEffect
	{
	public:
		BlinkLightEffect();
	protected:
		~BlinkLightEffect();
	public:
		virtual void buildPropertyMap();
		virtual void apply(CoreBase::ActorBase* actor);
		virtual void unApply(CoreBase::ActorBase* actor);
		void update(osg::Vec3f eye);
		void setColor(osg::Vec4);
		osg::Vec4 getColor();
	private:
		bool									_updateOpen;
		osg::Timer_t							_startTick;
		osg::ref_ptr<BlinkLightUpdateCallback>	_cb;
		osg::Vec3								_meshDrawableActorPos;
	};

	class BlinkLightUpdateCallback : public osg::NodeCallback
	{
	public:
		BlinkLightUpdateCallback(BlinkLightEffect* be,osgViewer::View* view)
		{
			_be = be;
			_v = view;
		}
		~BlinkLightUpdateCallback(){};
		virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
		{
			if(!_be)
				return ;
			osg::Vec3f centre,up,eye;
			_v->getCamera()->getViewMatrixAsLookAt(eye,centre,up);
			_be->update(eye);
		}
	protected:
		BlinkLightEffect*					_be ;
		osgViewer::View*					_v;
	};
}